package lang

import (
	"gvm/native/basic"
	"gvm/rtda"
	"math"
)

func RegisterDouble() (className string, methods []*basic.NaMethod) {
	return "java/lang/Double", []*basic.NaMethod{
		{
			"doubleToRawLongBits",
			"(D)J",
			doubleToRawLongBits,
		}, {
			"longBitsToDouble",
			"(J)D",
			longBitsToDouble,
		},
	}
}

// public static native long doubleToRawLongBits(double value);
// (D)J
func doubleToRawLongBits(jFrame *rtda.JFrame) {
	value := jFrame.LocalVars().GetDouble(0)
	bits := math.Float64bits(value) // todo
	jFrame.OperandStack().PushLong(int64(bits))
}

// public static native double longBitsToDouble(long bits);
// (J)D
func longBitsToDouble(jFrame *rtda.JFrame) {
	bits := jFrame.LocalVars().GetLong(0)
	value := math.Float64frombits(uint64(bits)) // todo
	jFrame.OperandStack().PushDouble(value)
}
